import numpy as np
import matplotlib.pyplot as plt

N = 100
def Runge(x):
    return 1.0 / (1 + 25 * x**2)

def func1(x):
    return 0.0384615+0.153846*(x+1)+1.05769*(x+1)*(x+0.6)-1.92308*(x+1)*(x+0.6)*(x+0.2)+1.20192*(x+1)*(x+0.6)*(x+0.2)*(x-0.2)-5.55112e-16*(x+1)*(x+0.6)*(x+0.2)*(x-0.2)*(x-0.6)

def func2(x):
    return 0.0384615+0.10181*(x+1)+0.260181*(x+1)*(x+0.8)+0.791855*(x+1)*(x+0.8)*(x+0.6)+2.68665*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)-6.36312*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)-17.6753*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)*(x)+84.8416*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)*(x)*(x-0.2)-167.916*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)*(x)*(x-0.2)*(x-0.4)+220.942*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)*(x)*(x-0.2)*(x-0.4)*(x-0.6)-220.942*(x+1)*(x+0.8)*(x+0.6)*(x+0.4)*(x+0.2)*(x)*(x-0.2)*(x-0.4)*(x-0.6)*(x-0.8)
 
def func3(x):
    return 0.0384615+0.0907519*(x+1)+0.184745*(x+1)*(x+0.866667)+0.388937*(x+1)*(x+0.866667)*(x+0.733333)+0.892711*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)+2.15227*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)+3.18957*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)-29.2886*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)-71.7654*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)+605.326*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)-1661.53*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)+2808.21*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)*(x-0.333333)-3334.75*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)*(x-0.333333)*(x-0.466667)+2835.21*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)*(x-0.333333)*(x-0.466667)*(x-0.6)-1518.86*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)*(x-0.333333)*(x-0.466667)*(x-0.6)*(x-0.733333)+2.6148e-12*(x+1)*(x+0.866667)*(x+0.733333)*(x+0.6)*(x+0.466667)*(x+0.333333)*(x+0.2)*(x+0.0666667)*(x-0.0666667)*(x-0.2)*(x-0.333333)*(x-0.466667)*(x-0.6)*(x-0.733333)*(x-0.866667)

def func4(x):
    return 0.0384615+0.0859729*(x+1)+0.158371*(x+1)*(x+0.9)+0.286007*(x+1)*(x+0.9)*(x+0.8)+0.533595*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)+1.03775*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)*(x+0.6)+2.0019*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)*(x+0.6)*(x+0.5)+2.79677*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)*(x+0.6)*(x+0.5)*(x+0.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8)*(x+0.7)*(x+0.6)*(x+0.5)*(x+0.4)*(x+0.3)*(x+0.2)*(x+0.1)*(x)*(x-0.1)*(x-0.2)*(x-0.3)*(x-0.4)*(x-0.5)*(x-0.6)*(x-0.7)-260179*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)*(x+0.6)*(x+0.5)*(x+0.4)*(x+0.3)*(x+0.2)*(x+0.1)*(x)*(x-0.1)*(x-0.2)*(x-0.3)*(x-0.4)*(x-0.5)*(x-0.6)*(x-0.7)*(x-0.8)+260179*(x+1)*(x+0.9)*(x+0.8)*(x+0.7)*(x+0.6)*(x+0.5)*(x+0.4)*(x+0.3)*(x+0.2)*(x+0.1)*(x)*(x-0.1)*(x-0.2)*(x-0.3)*(x-0.4)*(x-0.5)*(x-0.6)*(x-0.7)*(x-0.8)*(x-0.9)

x = np.linspace(-1, 1, N)
plt.title("Chebyshev polynomial")
plt.plot(x, Runge(x), '--', label='f(x)')
plt.plot(x, func1(x), label='n=5')
plt.plot(x, func2(x), label='n=10')
plt.plot(x, func3(x), label='n=15')
plt.plot(x, func4(x), label='n=20')

plt.legend()
plt.savefig("C.png", dpi = 750, bbox_inches = 'tight')
